package com.tengju.bff.interfaces.shared;


import java.util.Optional;

public class InterfaceException extends RuntimeException {

    private final InterfaceCode code;
    private final String message;

    public InterfaceException(InterfaceCode code) {
        super(code.getMsg());
        message = code.getMsg();
        this.code = code;
    }

    public InterfaceException(InterfaceCode code, Object... param) {
        super(code.getMessage(param));
        message = code.getMessage(param);
        this.code = code;
    }

    public int getCode() {
        return code.getCode();
    }

    public String getMsg() {
        return code.getMsg();
    }

    @Override
    public String getMessage() {
        return Optional.ofNullable(message)
                .orElse(code.name());
    }
}
